package com.crazy.shell.provider.conf;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * Created by creazier.huang on 16/10/8.
 */
@Configuration
public class RedisConfig {
    @Autowired
    private RedisProperties cfg;

    @Bean(name = "jedisPool")
    public JedisPool initialPool(){
        JedisPoolConfig config = new JedisPoolConfig();
        BeanUtils.copyProperties(cfg,config);
        JedisPool jedisPool = new JedisPool(config,cfg.getHost(),cfg.getPort());
        return jedisPool;
    }

    @Bean(name="jedisTemp")
    public Jedis getClient(JedisPool pool){
        Jedis jedis = pool.getResource();
        return jedis;
    }
}
